package com.nondo.rdp.finance.domain.circle;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.hibernate.annotations.Where;
import org.hibernate.validator.constraints.Length;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.nondo.rdp.auth.domain.User;
import com.nondo.rdp.core.domain.attach.Attach;
import com.nondo.rdp.core.domain.base.BaseEntity;
import com.nondo.rdp.finance.config.DbConfig;

/**
 * 金融圈-说说
 */
@Entity
@Table(name = DbConfig.DEFAULT_TABLE_PREFIX + "circle", indexes = {@Index(columnList = "body")})
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
public class Circle extends BaseEntity {
	private static final long serialVersionUID = -952040619421934249L;
	private Long id;        //自增ID
    private String body;    //内容
    private User user;      //发布者
    private List<CircleComment> comments;//评论集合
    private List<CircleUp> ups;//点赞集合
    private List<Attach> attachList;// 图片

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Column(name = "body")
    @Length(min = 0, max = 255, message = "说说内容长度不能超过255个字符")
    public String getBody() {
        return body;
    }

    public void setBody(String body) {
        this.body = body;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "uid")
    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @OneToMany(mappedBy = "circle")
    @LazyCollection(LazyCollectionOption.EXTRA)
    @Where(clause = "del_flag='" + BaseEntity.DEL_FLAG_NORMAL + "'")
    public List<CircleComment> getComments() {
        return comments;
    }

    public void setComments(List<CircleComment> comments) {
        this.comments = comments;
    }

    @OneToMany(mappedBy = "circle")
    @LazyCollection(LazyCollectionOption.EXTRA)
    @Where(clause = "del_flag='" + BaseEntity.DEL_FLAG_NORMAL + "'")
    public List<CircleUp> getUps() {
        return ups;
    }

    public void setUps(List<CircleUp> ups) {
        this.ups = ups;
    }

    @OneToMany
    @LazyCollection(LazyCollectionOption.EXTRA)
    public List<Attach> getAttachList() {
        return attachList;
    }

    public void setAttachList(List<Attach> attachList) {
        this.attachList = attachList;
    }
}
